//
//  GWBaseViewController.m
//  shandsHotel
//
//  Created by zh_s on 2018/9/25.
//  Copyright © 2018年 zh_s. All rights reserved.
//

#import "GWBaseViewController.h"

@interface GWBaseViewController ()<GWNavigationViewDelegate,LoadingViewDelegate>
@property (nonatomic,copy)NSString *titleText;
@end

@implementation GWBaseViewController


- (instancetype)initWithNavTitle:(NSString *)navTitle {
    self = [super init];
    if (self) {
        _titleText = navTitle;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.navigationBarHidden = YES;
    if (_NavigationType == NavigationTypeLight) {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    }else {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    }
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = BASE_BACKCOLOR;
//    contentInsetAdjustmentBehavior
//    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;
    [self initNav];
    self.fd_prefersNavigationBarHidden = YES;
//    self.fd_interactivePopDisabled = YES;
}
- (void)initNav {
    GWNavigaitionView *nav = [[GWNavigaitionView alloc]initWithTitle:_titleText withLeftTitle:@"Icon_Navigation Bar_Back"];
    nav.delegate = self;
    nav.backgroundColor = [UIColor whiteColor];
//    [nav settingShadowOpacity:0.2 withShadowColor:RGB(153, 153, 153) wihtShadowRadius:5 withshadowOffset:CGSizeMake(0, 3)];

//    nav.backgroundColor = RGB(34, 49, 72);
    nav.leftTitle = @"Icon_Navigation Bar_Back.png";
    [self.view addSubview:nav];

    _nav = nav;
}

//将自定义导航栏提到最前边
- (void)bringNavToFront {
    [self.view bringSubviewToFront:_nav];
}
//重写setTitleView方法
- (void)setTitleView:(UIView *)titleView {
    _titleView = titleView;
    _nav.titleView = titleView;
}
//重写setNavTitle方法
- (void)setNavTitle:(NSString *)navTitle {
    if (_navTitle != navTitle) {
        _navTitle = navTitle;
    }
    _nav.titleLabel.text = navTitle;
}
//重写leftTitle方法
- (void)setLeftTitle:(NSString *)leftTitle {
    if (_leftTitle != leftTitle) {
        _leftTitle = leftTitle;
    }
    _nav.leftTitle = leftTitle;
}
//重写setRightTitle方法
- (void)setRightTitle:(NSString *)rightTitle {
    if (_rightTitle != rightTitle) {
        _rightTitle = rightTitle;
    }
    _nav.rightTitle = rightTitle;
}
//重写导航栏背景色
- (void)setNavBackgroundColor:(UIColor *)navBackgroundColor {
    _navBackgroundColor = navBackgroundColor;
    _nav.backgroundColor = navBackgroundColor;
}
/**导航栏左侧按钮点击事件*/
- (void)leftViewClick {
    if (_isPresendeView == YES) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    if (self.navigationController) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)setIsShadow:(BOOL)isShadow {
    _isShadow = isShadow;
    if (isShadow) {
        [self.nav settingShadowOpacity:0.2 withShadowColor:RGB(153, 153, 153) wihtShadowRadius:5 withshadowOffset:CGSizeMake(0, 3)];


    }
}

- (NSString *)phoneStr {
//    phoneStr =
    return _phoneStr;
}

/**导航栏右侧按钮点击事件*/
- (void)rightViewClick {
    JTDLog(@"如果输出这个说明没有重写右边按钮的方法啦");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (LoadingView *)loading {
    if (!_loading) {
        NSString *tips;
        if (IsStrEmpty(_loadingTips)) {
            tips = @"加载中…";
        }else {
            tips = _loadingTips;
        }

        CGFloat timeDelay;
        if (_loadingTimeDelay == 0) {
            timeDelay = TIMEOUTINTERVALSECOND;
        }else {
            timeDelay = _loadingTimeDelay;
        }
        _loading = [LoadingView shareManagerInView:self.view withTips:tips withTimeDelay:timeDelay];
        _loading.delegate = self;
        _loading.tag = 99999;
    }
    return _loading;
}
- (void)endLoading {
    [_loading removeFromSuperview];
    _loading = nil;
}


/**导航栏颜色类型*/
//- (void)setNavigationType:(NavigationType)NavigationType {
//    if (NavigationType == 1) {
//        self.nav.backgroundColor = [UIColor whiteColor];
//        self.nav.titleLabel.textColor = RGB(17, 17, 17);
//        UIView *leftView = self.nav.leftView;
//        if ([leftView isKindOfClass:[UIImageView class]]) {
//            UIImageView *imageView = (UIImageView *)leftView;
//            imageView.image = IMAGE_NAME(@"page_back_black");
//        }
//
//
//        UIView *rightView = self.nav.rightView;
//        if ([rightView isKindOfClass:[UILabel class]]) {
//            UILabel *label = (UILabel *)rightView;
//            label.textColor = RGB(17, 17, 17);
//        }
//    }
//}
- (void)dealloc {
    JTDLog(@"销毁了%@",self);
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
